package com.ruoyi.web.controller.shopping;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.order.domain.StoreProductOrder;
import com.ruoyi.order.service.IStoreProductOrderService;
import com.ruoyi.shopping.domain.MallOrder;
import com.ruoyi.shopping.service.IMallOrderService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.constant.DicConstants;
import com.ruoyi.shopping.domain.MallComment;
import com.ruoyi.shopping.service.IMallCommentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品评价Controller
 *
 * @author scx
 * @date 2022-06-10
 */
@RestController
@RequestMapping("/shopping/comment")
public class MallCommentController extends BaseController
{
    @Autowired
    private IMallCommentService mallCommentService;

    @Autowired
    private IMallOrderService mallOrderService;
    /**
     * 查询商品评价列表
     */
    @PreAuthorize("@ss.hasPermi('shopping:comment:list')")
    @GetMapping("/list")
    public TableDataInfo list(MallComment mallComment)
    {
        startPage();
        mallComment.getParams().put("PlatformContent1",mallComment.getPlatformContent());
        List<MallComment> mallComments = mallCommentService.selectMallCommentList(mallComment);
        return getDataTable(mallComments);



    }

    /**
     * 导出商品评价列表
     */
    @PreAuthorize("@ss.hasPermi('shopping:comment:export')")
    @Log(title = "商品评价", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(MallComment mallComment)
    {
        List<MallComment> list = mallCommentService.selectMallCommentList(mallComment);
        ExcelUtil<MallComment> util = new ExcelUtil<MallComment>(MallComment.class);
        return util.exportExcel(list, "商品评价数据");
    }

    /**
     * 获取商品评价详细信息
     */
    @PreAuthorize("@ss.hasPermi('shopping:comment:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(mallCommentService.selectMallCommentById(id));
    }

    /**
     * 新增商品评价
     */
    @PreAuthorize("@ss.hasPermi('shopping:comment:add')")
    @Log(title = "商品评价", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallComment mallComment)
    {
        return toAjax(mallCommentService.insertMallComment(mallComment));
    }

    /**
     * 修改商品评价
     */
    @PreAuthorize("@ss.hasPermi('shopping:comment:edit')")
    @Log(title = "商品评价", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallComment mallComment)
    {
        mallComment.setPlatformContentTime(new Date());
        mallComment.setUpdateType(DicConstants.BUSINESS_Manager.getCode());
        return toAjax(mallCommentService.updateMallComment(mallComment));
    }

    /**
     * 删除商品评价
     */
    @PreAuthorize("@ss.hasPermi('shopping:comment:remove')")
    @Log(title = "商品评价", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mallCommentService.logicDeleteMallComment(ids,DicConstants.BUSINESS_Manager.getCode(),SecurityUtils.getUserId()));
    }
}
